#!/usr/bin/perl 
use strict;
use warnings;
use File::Spec::Functions;

our %params = (
    dmoz_dir     => '/home/xuqy/Desktop/dmoz',
);

chdir $params{dmoz_dir} or die "$!";
my @dirs = ('Top');
my $count = 0;
while (@dirs) {
    my $dir = shift @dirs; 
    opendir DIR, $dir or die "cannot open $dir: $!";
    my @subDirs;
    while (my $entry = readdir DIR) {
        next if $entry =~ /^\.{1,2}$/;
        my $entry = catfile($dir, $entry);
        if (-l $entry) {
            unlink $entry;
            $count++;
        }
        elsif (-d $entry) {
            push @subDirs, $entry;
        }
    }
    closedir DIR;
    unshift @dirs, @subDirs;
}
print "Done! $count symbolic links was removed.\n";


